<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no,minimal-ui"/>
    <title>highcharts图表报表</title>
    <link rel="stylesheet" href="css/charts_demo.css">
    <script src="js/vuejs-2.5.16.js"></script>
    <script src="js/axios-0.18.0.js"></script>
    <script src="js/highcharts.js"></script>
    <script src="js/highcharts-3d.js"></script>
    <script src="js/highcharts-more.js"></script>
    <script src="js/drilldown.js"></script>
</head>
<body>
<div id="app" class="my-box">
    <div class="my-box-left">
        <button @click="columnCharts">统计各部门人数</button>
        <br/> <br/>
        <button @click="lineCharts">月份入职人数统计</button>
        <br/> <br/>
        <button @click="pieCharts">员工地方来源统计</button>
        <br/> <br/>
    </div>
    <div class="my-box-right">
        <div id="container" style="height:450px;"></div>
    </div>
</div>
</body>

<script>
    new Vue({
        el: "#app",
        data: {},
        methods: {
            columnCharts() {
                axios.get("/stat/columnCharts").then(res => {
                    let datas = res.data;
                    let titles = [];  //x轴上显示的数据
                    let values = []; //y轴上显示的数据
                    for (let i = 0; i < datas.length; i++) {
                        titles[i] = datas[i].deptName;
                        values[i] = datas[i].num;
                    }
                    Highcharts.chart('container', {
                        chart: {
                            type: 'column'
                        },
                        title: {
                            text: '各部门人数'
                        },
                        xAxis: {
                            categories: titles,
                            crosshair: true
                        },
                        yAxis: {
                            min: 0,
                            title: {
                                text: '人数'
                            }
                        },
                        tooltip: {
                            // head + 每个 point + footer 拼接成完整的 table
                            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                                '<td style="padding:0"><b>{point.y:.1f} </b></td></tr>',
                            footerFormat: '</table>',
                            shared: true,
                            useHTML: true
                        },
                        plotOptions: {
                            column: {
                                borderWidth: 0
                            }
                        },
                        series: [{
                            name: '各部门人数',
                            data: values
                        }]
                    });


                })
            },
            lineCharts() {
                axios.get("/stat/lineCharts").then(res => {
                    let datas = res.data;
                    let values = []; //y轴上显示的数据
                    for (let i = 0; i < datas.length; i++) {
                        values[i] = datas[i].num;
                    }
                    var chart = Highcharts.chart('container', {
                        title: {
                            text: '月份入职人数统计'
                        },
                        yAxis: {
                            title: {
                                text: '入职人数'
                            }
                        },
                        legend: {
                            layout: 'vertical',
                            align: 'right',
                            verticalAlign: 'middle'
                        },
                        plotOptions: {
                            series: {
                                label: {
                                    connectorAllowed: false
                                },
                                pointStart: 2010
                            }
                        },
                        series: [{
                            name: '入职人数',
                            data: values
                        }],
                        responsive: {
                            rules: [{
                                condition: {
                                    maxWidth: 500
                                },
                                chartOptions: {
                                    legend: {
                                        layout: 'horizontal',
                                        align: 'center',
                                        verticalAlign: 'bottom'
                                    }
                                }
                            }]
                        }
                    });

                })
            },
            pieCharts() {
                axios.get("/stat/pieCharts").then(res => {
                    let datas = res.data;
                    Highcharts.chart('container', {
                        chart: {
                            type: 'column'
                        },
                        title: {
                            text: '公司原因地方来源'
                        },
                        xAxis: {
                            type: 'category'
                        },
                        yAxis: {
                            title: {
                                text: '人数'
                            }
                        },
                        legend: {
                            enabled: false
                        },
                        plotOptions: {
                            series: {
                                borderWidth: 0,
                                dataLabels: {
                                    enabled: true,
                                    format: '{point.y}'
                                }
                            }
                        },
                        tooltip: {
                            headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
                            pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y}</b><br/>'
                        },
                        series: [{
                            name: '省份',
                            colorByPoint: true,
                            data: datas
                        }],
                        drilldown: {
                            series: datas
                        }
                    });

                })
            }
        }
    });
</script>
</html>